bitmasks constructive algorithms greedy sortings *800

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n = int(input())
    l = [*(int(x) for x in input().split() if int(x)%2==0)]; m = len(l)
    if(m==0): print(0)
    elif(m<n): print(len(l))
    else:
        mi = 10**11
        for i in l:
            e = (bin(i)[::-1].index("1"))
            mi = min(mi,e)
        print(mi+m-1)

C++ Code:

// Problem: B. Patchouli's Magical Talisman
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-falign-functions,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3,2)
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<map>
#include<set>
#include<list>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<ostream>
#include<numeric>
#include<limits.h>
#include<iostream>
#include<iterator>
#include<algorithm>
#include<functional>
#include<unordered_set>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using i64=long long;
#define int long long
#define ull unsigned long long
#define PII pair<int,int>
#define puts(res) cout<<res<<'\n'
#define debug(a) cout<<#a<<"="<<a<<endl
#define debug2(a,b) cout<<#a<<"="<<a<<" "<<#b<<"="<<b<<endl
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define mem(a) memset(a,0x3f,sizeof(a))
#define fup(o,a,b) for(int o=a;o<=b;o++)
#define up(a,b) for(int o=a;o<=b;o++)
#define dn(a,b) for(int o=a;o>=b;o--)
#define fdn(o,a,b) for(int o=a;o>=b;o--)
#define show(a) for(auto it:a)cout<<it<<" ";
#define cvec(a) for(auto &it:a)cin>>it;
#define all(a) (a).begin(),(a).end()
#define YES {puts("YES");return;}
#define NO {puts("NO");return;}
#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define endl '\n'
#define fi first
#define se second
#define pb emplace_back
#define pob pop_back
#define pof pop_front
#define pf emplace_front
#define db double
#define MAX 0x7ffffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
const int N=2e5+10;
int n,m;
int a[N];
int cnt[N];
int ans[N];
int lowbit(int x){
	return x&(-x);
}
void solve(){
	//try it again.
	cin>>n;
	up(1,n)cin>>a[o];
	up(1,n)cnt[o]=__lg(lowbit(a[o]));
	// up(1,n)cout<<cnt[o]<<" \n"[o==n];
	vector<int>idx;
	up(1,n)if(!cnt[o])idx.pb(o);
	if(idx.size()==0){
		cout<<*min_element(cnt+1,cnt+1+n)+n-1<<endl;
	}
	else{
		cout<<n-idx.size()<<endl;
	}
	// int last=-INF;
	// int now=
}
signed main(){
	IOS;
	int __;
	cin>>__;
	while(__--)
		solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set
1567B - MEXor Mixup
669A - Little Artem and Presents
691B - s-palindrome
851A - Arpa and a research in Mexican wave
811A - Vladik and Courtesy
1006B - Polycarp's Practice
1422A - Fence
21D - Traveling Graph
1559B - Mocha and Red and Blue
1579C - Ticks
268B - Buttons
898A - Rounding
1372B - Omkar and Last Class of Math
1025D - Recovering BST
439A - Devu the Singer and Churu the Joker
1323A - Even Subset Sum Problem
1095A - Repeating Cipher
630F - Selection of Personnel
630K - Indivisibility